import numpy as np
def rebuild (self ):
    # consistency checks
    list1 = self.imperfection_buckling_modes
    list2 = self.imperfection_scaling_factors
    diff = len( list1 ) - len( list2 )
    if diff <> 0:
        print 'WARNING - analysis using the *IMPERFECTION command' 
        print '          The number of buckling modes is different of the number of scaling factors'
        print '          The last scaling factor will be applied to all buckling modes'
        for i in range( diff ):
            list2.append( list2[ -1 ] ) 
    if self.axialInclude == False:
        self.separate_load_steps = False
        self.num_of_steps = 1
    if self.separate_load_steps == True:
        self.num_of_steps = 2 
    # angle in radians
    if self.alphadeg <> None:
        self.alpharad = np.pi * self.alphadeg / 180.
    if self.betadeg <> None:
        self.betarad = np.pi * self.betadeg / 180.
    # r2
    self.r2 = self.r
    if self.r <> None and self.h <> None and self.alpharad <> None:
        self.r2 = self.r - np.tan( self.alpharad ) * self.h
    # numel
    r  = self.r
    r2 = self.r2
    #bot part of the meridian
    #the following rule considers a rav (average) in which it assumes r2
    #    if r2 --> 0, and assumes r if r2 --> r
    rav = (( r - r2 )*r2/r + r2 )
    perav = 2 * np.pi * rav
    numel_r = self.numel_r
    if numel_r:
        self.elsize_r = 2*np.pi * self.r / numel_r # mm
    if self.numel_h:
        self.elsize_h = self.h / np.cos( self.alpharad ) / self.numel_h
    else:
        if self.numel_hr_ratio:
            self.elsize_h = self.elsize_r / self.numel_hr_ratio
        else:
            self.elsize_h = perav / numel_r
    

    #Rav = ((R-R2)*R2/R + R2)
    #
    #PERav = Rav * 2 * np.pi
    #MER_BOT_NUMEL = R_NUMEL * PPOINT * self.h/np.cos(self.alpharad) / PERav
    #RX, ZX = self.r_z_from_ppoint( PPOINT/2. )
    #part.seedEdgeByNumber( edges  = part.edges.findAt( ((RX,ZX,0),) ),
    #                       number = int(MER_BOT_NUMEL),
    #                       constraint = FREE,
    #                     )
    #top part of the meridian
#        MER_TOP_NUMEL = MER_BOT_NUMEL * (1.-PPOINT) / PPOINT
#        RX, ZX = self.r_z_from_ppoint( 0.5 + PPOINT/2. )
    # ploads
    self.ploadconf.rebuild()
    # allowables
    if self.allowables == None:
        print 'WARNING - using default allowables, check corbonfiber properties'
        self.allowables = (1741.,-855.,29.,-283.,98.,90.)
    # laminate parameters
    if self.using_lam_parameters and self.laminate_obj == None:
        import mapy
        mapy = reload( mapy )
        matobj = mapy.model.materials.matlamina.read_laminaprop(\
                    laminaprop = self.laminaprop)
        matobj.rebuild()
        if self.stack <> []:
            import mapy.model.properties.composite
            mapy.model.properties.composite = reload(
                mapy.model.properties.composite)
            lam = mapy.model.properties.composite.laminate.read_stack(\
                        stack  = self.stack,
                        plyt   = self.plyt,
                        matobj = matobj     )
            lam.rebuild()
            lam.calc_lamination_parameters()
            lam.calc_ABDE_from_lamination_parameters()
            self.laminate_obj = lam
        if self.stack == []:
            lam = mapy.model.properties.composite.laminate.Laminate() 
            lam.matobj = matobj
        self.laminate_obj = lam

    # jobname
    if self.study == None:
        extra = []
        if self.using_lam_parameters:
            extra.append( 'Lam_Par_yes' )
        if self.separate_load_steps:
            extra.append( '2_Steps' )
        if not self.axialInclude:
            extra.append( 'AxialDispl_no' )
        if not self.artificial_damping:
            extra.append( 'ArtDamp_no' )
        #
        tmp = [self.name] + extra + [self.meshname, self.ploadconf.name]
        while '' in tmp:
            tmp.remove( '' )
        self.jobname = '_'.join( tmp )
    else:
        tmp = [self.study.name] + [self.ploadconf.name]
        self.jobname = '_'.join( tmp )
    self.rebuilt = True
